add_library(math_internal STATIC math_internal.c)

add_library(math SHARED math.c)
target_link_libraries(math PRIVATE math_internal)

# The linker option "-Wl,--gc-sections" is needed because a dead unexported
# function (hidden) in the static library math_internal accesses an undefined
# external function. With "-Wl,--gc-sections" specified, such a dead unexported
# function will not be processed by the linker, therefore it is not a problem
# for the function to access an undefined symbol.
target_link_options(math
  PRIVATE "-Wl,--gc-sections"
  PRIVATE "-Wl,--verbose"
  PRIVATE "-Wl,--emit-relocs"
  PRIVATE "-Wl,--print-gc-sections"
  PRIVATE "-Wl,--icf=all"
  PRIVATE "-Wl,-T,${CMAKE_CURRENT_SOURCE_DIR}/math.ld")
